﻿<Window x:Class="SqlServerDataExporter.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="SqlServer Dataexporter" Height="600" Width="1000"
        xmlns:viewmodel="clr-namespace:SqlServerDataExporter" Closing="Window_Closing">
    
    <Window.Resources>
        <viewmodel:ViewModel x:Key="viewModel"/>
    </Window.Resources>
    <Grid DataContext="{StaticResource viewModel}">
        <DockPanel>

            <TabControl Grid.Column="0" Grid.Row="0"
                        Name="tabControl"
                        SelectedIndex="{Binding SelectedTabIndex, Mode=TwoWay}">
                
                
                <TabItem Header="Connections and Options" Name="tabItemConnectionString">
                    <DockPanel>

                        <Button DockPanel.Dock="Bottom" Click="Button_Connect">
                            Connect with connection string
                        </Button>
                        
                        <StackPanel>

                        <Label Content="Connection string:"/>

                        <TextBox Margin="0 0 0 25"
                                 Name="ConnectionString" Text="{Binding ConnectionString}" />
                            
                            <StackPanel Orientation="Horizontal">
                                <Label Width="100">Server: </Label>
                                <TextBox Width="200" Text="{Binding Server}"/>                             
                            </StackPanel>

                            <StackPanel Orientation="Horizontal">
                                <Label Width="100">Database:</Label>
                                <TextBox Width="200" Text="{Binding Database}"/>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" Margin="0 30 0 0">
                                <CheckBox Width="200" IsChecked="{Binding TrustedConnection}">Windows authentication</CheckBox>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal">
                                <Label Width="100">Username:</Label>
                                <TextBox Width="200"  
                                         Text="{Binding User}"
                                         IsEnabled="{Binding IsUsernamePasswordEnabled}"/>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal">
                                <Label Width="100">Password:</Label>
                                <TextBox Width="200" 
                                         Text="{Binding Password}"
                                         IsEnabled="{Binding IsUsernamePasswordEnabled}"/>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" Margin="0 10 0 0">
                                <Button Name="buttonBCS" Width="150" Click="Button_CreateConnectionString">build connection string</Button>                             
                            </StackPanel>

                        </StackPanel>

                        
                    </DockPanel>
                </TabItem>
                
                <TabItem Header="Tables" Name="tabItemTables">
                    <DockPanel>
                        
                        <Button DockPanel.Dock="Bottom" Name="buttonNexTabTables" Click="Button_NextTab">Next</Button>
                        
                        <ListBox Width="200"
                                 DockPanel.Dock="Left"
                                 ItemsSource="{Binding Tables}"
                                 SelectedItem="{Binding SelectedTable}">                           
                        </ListBox>

                        <ListBox ItemsSource="{Binding Columns}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Selected}" Content="{Binding .}"/>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                        
                    </DockPanel>
                </TabItem>

                <TabItem Header="Export" Name="tabItemExport">
                    <DockPanel>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="25"/>
                                <RowDefinition Height="25"/>
                            </Grid.RowDefinitions>
                            
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            
                            <TextBox Grid.Row="0" Grid.Column="0"
                                     Text="{Binding InsertStatements}"
                                     VerticalScrollBarVisibility="Visible" 
                                     TextWrapping="Wrap"
                                     AcceptsReturn="True"
                                     Name="textBoxSql"/>
                            
                            <StackPanel Grid.Column="0" Grid.Row="1" Orientation="Horizontal">
                                <RadioButton GroupName="export" 
                                             Name="radioButtonFile" 
                                             IsChecked="True"
                                             Margin="0 0 10 0">
                                    File
                                </RadioButton>
                                <RadioButton GroupName="export">
                                    In this Window
                                </RadioButton>
                            </StackPanel>
                            <StackPanel Grid.Row="2" Orientation="Horizontal">
                                <TextBox Width="400" Text="{Binding FileName}"/>                                                                    
                                <Button Click="Button_SelectFile">
                                    ...
                                </Button>
                            </StackPanel>

                            <StackPanel Grid.Row="3" Orientation="Horizontal">
                                <Label>Rows exported: </Label>
                                <Label Content="{Binding RowsExported}"/>
                            </StackPanel>
                            
                            <Label Grid.Row="4" Content="{Binding ErrorInApp}" Foreground="Red"/>

                            <Button Grid.Row="5" Grid.Column="0"
                                    Click="Button_ExportData" 
                                    Content="{Binding ExportText}"/>
                        </Grid>
                    </DockPanel>
                </TabItem>
                
                <TabItem Header="Binary &lt;-> hex converter" Name="tabItemBinaryConverter">
                    <DockPanel>
                        <Label DockPanel.Dock="Top">Save a hexstring as a binary file ore vice versa</Label>
                        <StackPanel DockPanel.Dock="Bottom">
                            <Button Click="Button_LoadBinaryAsHexString">Load from file</Button>
                            <Button Click="Button_SaveHexStringAsBinary">Save to file</Button>                            
                        </StackPanel>
                        <TextBox Name="textBoxHexString" 
                                 TextWrapping="Wrap"
                                 Text="{Binding BinaryHexString}"/>                        
                    </DockPanel>                    
                </TabItem>
                
                
            </TabControl>
        </DockPanel>
    </Grid>
</Window>
